package com.example.pipibee.controller;

import com.example.pipibee.pojo.param.*;
import com.example.pipibee.pojo.vo.DoctorSelectDiaVO;
import com.example.pipibee.pojo.vo.DoctorSelectMrinVO;
import com.example.pipibee.pojo.vo.DoctorSelectSurVO;
import com.example.pipibee.pojo.vo.PageBean;
import com.example.pipibee.service.DoctorService;
import com.example.pipibee.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pipibee/doctor")
@Validated
@Api(tags = "1.1. 医生端")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    public DoctorController() {
        log.debug("创建控制器类对象：DoctorController");
    }

    @ApiOperation("插入_住院病案_主表")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new-mrin")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "患者姓名", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "birthday", value = "患者生日", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "gender", value = "患者性别", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "idCard", value = "身份证", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "bloodType", value = "患者血型", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "symptoms", value = "患者症状", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "doctor", value = "住院医师", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "admissionMethod", value = "入院方式", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dischargeMethod", value = "出院方式", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
    })
    public JsonResult addNewMr(@RequestBody @Validated DoctorInsertParam doctorInsertParam) {
        log.debug("开始处理【插入_住院病案_主表】的请求，参数：{}", doctorInsertParam);
        doctorService.addNewMrin(doctorInsertParam);
        return JsonResult.ok();
    }

    @ApiOperation("插入_住院病案_诊断表")
    @ApiOperationSupport(order = 200)
    @PostMapping("/add-new-dia")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrInId", value = "住院病案ID", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "mrNum", value = "病案号", required = false, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "diaType", value = "诊断类型", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "diaData", value = "诊断内容", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "therapeuticEffect", value = "疗效", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
    })
    public JsonResult addNewDia(@RequestBody @Validated DoctorDiaInsertParam doctorDiaInsertParam) {
        log.debug("开始处理【插入_住院病案_诊断表】的请求，参数：{}", doctorDiaInsertParam);
        doctorService.addNewDia(doctorDiaInsertParam);
        return JsonResult.ok();
    }

    @ApiOperation("插入_住院病案_手术表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/add-new-sur")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrInId", value = "住院病案ID", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "mrNum", value = "病案号", required = false, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "surType", value = "手术类型", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "surData", value = "手术记录", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "postoperativeRecovery", value = "术后恢复情况", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "doctor", value = "主刀医师", required = true, dataType = "String", paramType = "body",dataTypeClass = String.class),
    })
    public JsonResult addNewSur(@RequestBody @Validated DoctorSurInsertParam doctorSurInsertParam) {
        log.debug("开始处理【插入_住院病案_诊断表】的请求，参数：{}", doctorSurInsertParam);
        doctorService.addNewSur(doctorSurInsertParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量删除_住院病案_诊断表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/delete-dia")
    @ApiImplicitParams({

    })
    public JsonResult deleteDia(@RequestBody @Validated DoctorDiaDeleteParam doctorDiaDeleteParam) {
        log.debug("开始处理【批量删除_住院病案_诊断表】的请求，参数：{}", doctorDiaDeleteParam);
        doctorService.deleteDia(doctorDiaDeleteParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量删除_住院病案_手术表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/delete-sur")
    @ApiImplicitParams({

    })
    public JsonResult deleteSur(@RequestBody @Validated DoctorSurDeleteParam doctorSurDeleteParam) {
        log.debug("开始处理【批量删除_住院病案_手术表】的请求，参数：{}", doctorSurDeleteParam);
        doctorService.deleteSur(doctorSurDeleteParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量删除_住院病案_主表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/delete-mrin")
    @ApiImplicitParams({

    })
    public JsonResult deleteAllMrin(@RequestBody @Validated DoctorDeleteAllMrinParam doctorDeleteAllMrinParam) {
        log.debug("开始处理【批量删除_住院病案_主表】的请求，参数：{}", doctorDeleteAllMrinParam);
        doctorService.deleteAllMrin(doctorDeleteAllMrinParam);
        return JsonResult.ok();
    }

    @ApiOperation("修改_住院病案_主表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update-mrin")
    @ApiImplicitParams({

    })
    public JsonResult updateMrin(@RequestBody @Validated DoctorUpdateMrinParam doctorUpdateMrinParam) {
        log.debug("开始处理【修改_住院病案_主表】的请求，参数：{}", doctorUpdateMrinParam);
        doctorService.updateMrin(doctorUpdateMrinParam);
        return JsonResult.ok();
    }

    @ApiOperation("修改_诊断表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update-dia")
    @ApiImplicitParams({

    })
    public JsonResult updateDia(@RequestBody @Validated DoctorDiaUpdateParam doctorDiaUpdateParam) {
        log.debug("开始处理【修改_诊断表】的请求，参数：{}", doctorDiaUpdateParam);
        doctorService.updateDia(doctorDiaUpdateParam);
        return JsonResult.ok();
    }

    @ApiOperation("修改_手术表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update-sur")
    @ApiImplicitParams({

    })
    public JsonResult updateSur(@RequestBody @Validated DoctorSurUpdateParam doctorSurUpdateParam) {
        log.debug("开始处理【修改_手术表】的请求，参数：{}", doctorSurUpdateParam);
        doctorService.updateSur(doctorSurUpdateParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量出院")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update-discharge")
    @ApiImplicitParams({

    })
    public JsonResult discharge(@RequestBody @Validated DoctorDischargeParam doctorDischargeParam) {
        log.debug("开始处理【批量出院】的请求，参数：{}", doctorDischargeParam);
        doctorService.discharge(doctorDischargeParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量提交")
    @ApiOperationSupport(order = 300)
    @PostMapping("/submit")
    @ApiImplicitParams({

    })
    public JsonResult submit(@RequestBody @Validated DoctorSubmitParam doctorSubmitParam) {
        log.debug("开始处理【批量提交】的请求，参数：{}", doctorSubmitParam);
        doctorService.submit(doctorSubmitParam);
        return JsonResult.ok();
    }

    @ApiOperation("批量审批")
    @ApiOperationSupport(order = 300)
    @PostMapping("/approval")
    @ApiImplicitParams({

    })
    public JsonResult approval(@RequestBody @Validated DoctorApprovalParam doctorApprovalParam) {
        log.debug("开始处理【批量审批】的请求，参数：{}", doctorApprovalParam);
        doctorService.approval(doctorApprovalParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询填充_手术表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/select-update-sur")
    @ApiImplicitParams({

    })
    public JsonResult updateSurSelect(@RequestBody @Validated DoctorSurUpdateSelectParam doctorSurUpdateSelectParam) {
        log.debug("开始处理【查询填充_手术表】的请求，参数：{}", doctorSurUpdateSelectParam);
        return JsonResult.ok(doctorService.updateSurSelect(doctorSurUpdateSelectParam));
    }

    @ApiOperation("查询填充_诊断表")
    @ApiOperationSupport(order = 300)
    @PostMapping("/select-update-dia")
    @ApiImplicitParams({

    })
    public JsonResult updateDiaSelect(@RequestBody @Validated DoctorDiaUpdateSelectParam doctorDiaUpdateSelectParam) {
        log.debug("开始处理【查询填充_诊断表】的请求，参数：{}", doctorDiaUpdateSelectParam);
        return JsonResult.ok(doctorService.updateDiaSelect(doctorDiaUpdateSelectParam));
    }

    @ApiOperation("查询_住院病案_简略列表")
    @ApiOperationSupport(order = 400)
    @PostMapping("/select-list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrNumber", value = "病案号", required = false, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "name", value = "患者姓名", required = false, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "idCard", value = "身份证", required = false, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "doctor", value = "住院医师", required = false, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "admissionMethod", value = "入院方式", required = false, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dischargeMethod", value = "出院方式", required = false, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "approvalStatus", value = "病案状态", required = false, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "gmtCreate", value = "数据创建时间", required = false, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "gmtModified", value = "最后修改时间", required = false, dataType = "String", paramType = "body",dataTypeClass = String.class),
            @ApiImplicitParam(name = "page", value = "查询页面", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, dataType = "Integer", paramType = "body",dataTypeClass = Integer.class),
    })
    public JsonResult selectList(@RequestBody @Validated DoctorListSelectParam doctorListSelectParam) {
        log.debug("开始处理【查询_住院病案_简略列表】的请求，参数：{}", doctorListSelectParam);
        PageBean pageBean = doctorService.selectList(doctorListSelectParam);
        return JsonResult.ok(pageBean);
    }

    @ApiOperation("查询_住院病案_主表")
    @ApiOperationSupport(order = 500)
    @PostMapping("/select-mrin")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrNum", value = "病案号", required = true, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
    })
    public JsonResult selectMrin(@RequestBody @Validated DoctorDataSelectParam doctorDataSelectParam) {
        log.debug("开始处理【查询_住院病案_主表】的请求，参数：{}", doctorDataSelectParam);
        DoctorSelectMrinVO doctorSelectMrinVO = doctorService.selectMrin(doctorDataSelectParam);
        return JsonResult.ok(doctorSelectMrinVO);
    }

    @ApiOperation("查询_住院病案_诊断表")
    @ApiOperationSupport(order = 600)
    @PostMapping("/select-dia")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrNum", value = "病案号", required = true, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
    })
    public JsonResult selectDia(@RequestBody @Validated DoctorDataSelectParam doctorDataSelectParam) {
        log.debug("开始处理【查询_住院病案_诊断表】的请求，参数：{}", doctorDataSelectParam);
        List<DoctorSelectDiaVO> doctorSelectDiaVOS = doctorService.selectDia(doctorDataSelectParam);
        return JsonResult.ok(doctorSelectDiaVOS);
    }

    @ApiOperation("查询_住院病案_手术表")
    @ApiOperationSupport(order = 700)
    @PostMapping("/select-sur")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mrNum", value = "病案号", required = true, dataType = "Long", paramType = "body",dataTypeClass = Long.class),
    })
    public JsonResult selectSur(@RequestBody @Validated DoctorDataSelectParam doctorDataSelectParam) {
        log.debug("开始处理【查询_住院病案_手术表】的请求，参数：{}", doctorDataSelectParam);
        List<DoctorSelectSurVO> doctorSelectSurVOS = doctorService.selectSur(doctorDataSelectParam);
        return JsonResult.ok(doctorSelectSurVOS);
    }

    @ApiOperation("住院病案_简略列表_Excel导出")
    @ApiOperationSupport(order = 700)
    @PostMapping("/export")
    public void export(@RequestBody @Validated DoctorListSelectParam doctorListSelectParam, HttpServletResponse response) {
        log.debug("开始处理【住院病案_简略列表_Excel导出】的请求，参数：{},{}", doctorListSelectParam, response);
        doctorService.export(doctorListSelectParam, response);
    }

}
